package com.crayon.util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.crayon.account.ActivityCompose;
import com.crayon.account.ActivityComposeMenu;
import com.crayon.account.dao.DAOAccount;
import com.crayon.account.dao.DAOCardBank;
import com.crayon.account.dao.DAOCategory;
import com.crayon.account.dao.DAOFood;
import com.crayon.account.data.EDAType;
import com.crayon.account.data.ItemList;
import com.crayon.account.fragments.FragmentRGWrite;
import com.crayon.account.fragments.FragmentWriteFood;
import com.crayon.account.fragmentspop.FragmentPopComm;
import com.crayon.account.fragmentspop.FragmentPopEditBank;
import com.crayon.account.fragmentspop.FragmentPopEditCate;
import com.crayon.account.impl.OnDialogFragment;

public class UTILSC {

	public static void bindWrite(Activity activity){
		
	}

	
	/**
	 * 
	 * @param item
	 * @return
	 */
	public static boolean isINCOMECheckIOType(DAOAccount item){
		if(item.getxIOType()==EDAType.INCOM.getKey() || item.getxIOType()==EDAType.FIXEDINCOM.getKey()){
			return true;
			
		}else if(item.getxIOType()==EDAType.OUTCOM.getKey() || item.getxIOType()==EDAType.FIXEDOUTCOM.getKey()){
			return false;
		}
		return false;
	}
	
	public static void addOnPopWriteFragment(FragmentActivity activity,DAOAccount item
			,OnDialogFragment dialogFragment){
//		FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
//		Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(FragmentPopComm.class.getName());
//		if (prev != null) {
//			ft.remove(prev);
//		}
//		ft.addToBackStack(null);
//		FragmentPopComm newFragment = FragmentPopComm.newInstance(item);
//		newFragment.setOnDialogFragment(dialogFragment);
//		newFragment.show(ft, FragmentPopComm.class.getName());

		Intent intent = new Intent(activity,ActivityCompose.class);
		if(item!=null){
			Bundle bundle = new Bundle();
			bundle.putSerializable(FragmentRGWrite.PARAM_DAO, item);
			intent.putExtras(bundle);
		}
		activity.startActivityForResult(intent, 0);
	}

	public static void pushActivityComposeFood(Activity activity,DAOFood item){

		Intent intent = new Intent(activity,ActivityComposeMenu.class);
		if(item!=null){
			Bundle bundle = new Bundle();
			bundle.putSerializable(FragmentWriteFood.PARAM_DAO, item);
			intent.putExtras(bundle);
		}
		activity.startActivityForResult(intent, 0);

	}
	public static void addOnPopEditCate(FragmentActivity activity,ItemList item
			,OnDialogFragment dialogFragment){
		FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
		Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(FragmentPopComm.class.getName());
		if (prev != null) {
			ft.remove(prev);
		}
		ft.addToBackStack(null);
		if(item.getTag()!=null){
			if(item.getTag() instanceof DAOCardBank){
				FragmentPopEditBank newFragment = FragmentPopEditBank.newInstance(item);
				newFragment.setOnDialogFragment(dialogFragment);
				newFragment.show(ft, FragmentPopComm.class.getName());
				
			}else if(item.getTag() instanceof DAOCategory){
				FragmentPopEditCate newFragment = FragmentPopEditCate.newInstance(item);
				newFragment.setOnDialogFragment(dialogFragment);
				newFragment.show(ft, FragmentPopComm.class.getName());
			}
		}
		
		
	}
}
